package com.sunyard.client2.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.sunyard.client.SunEcmClientApi;
import com.sunyard.client.bean.ClientHeightQuery;
import com.sunyard.client2.ConnectionFactory;
import com.sunyard.client2.conf.ConfUtil;
import com.sunyard.client2.util.StringUtil;
import com.sunyard.util.DateUtil;

public class HeightQuery extends JPanel {
	private JTextField textField1;
	private JTextField textField2;
	private JTextField textField3;
	private JTextField textField11;
	private JTextField textField22;
	private JTextField textField33;
	private JLabel lblNewLabel_3;
	private JTextField textField;
	private JLabel lblNewLabel_4;
	private JTextField textField_1;

	/**
	 * Create the panel.
	 */
	public HeightQuery() {
		setLayout(null);

		JLabel lblNewLabel = new JLabel("条件1:");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(32, 40, 54, 15);
		add(lblNewLabel);

		textField1 = new JTextField();
		textField1.setBounds(128, 37, 178, 21);
		textField1.setText(ConfUtil.getString("userAttr1", ""));
		add(textField1);
		textField1.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("条件2:");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(32, 77, 54, 15);
		add(lblNewLabel_1);

		textField2 = new JTextField();
		textField2.setBounds(128, 77, 178, 21);
		textField2.setText(ConfUtil.getString("userAttr2", ""));
		add(textField2);
		textField2.setColumns(10);

		JLabel lblNewLabel_2 = new JLabel("条件3:");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_2.setBounds(32, 122, 54, 15);
		add(lblNewLabel_2);

		textField3 = new JTextField();
		textField3.setBounds(128, 119, 178, 21);
		textField3.setText(ConfUtil.getString("userAttr3", ""));
		add(textField3);
		textField3.setColumns(10);

		textField11 = new JTextField();
		textField11.setColumns(10);
		textField11.setBounds(341, 34, 178, 21);
		textField11.setText(DateUtil.get8bitDateStr());
		add(textField11);

		textField22 = new JTextField();
		textField22.setColumns(10);
		textField22.setBounds(341, 74, 178, 21);
		add(textField22);

		textField33 = new JTextField();
		textField33.setColumns(10);
		textField33.setBounds(341, 116, 178, 21);
		add(textField33);

		JButton btnNewButton = new JButton("查询");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ClientHeightQuery heightQuery = new ClientHeightQuery();
				heightQuery.setUserName(ConfUtil.getString("userName", ""));
				heightQuery.setPassWord(ConfUtil.getString("passWord", ""));
				heightQuery.setLimit(Integer.parseInt(textField_1.getText()));
				heightQuery.setPage(Integer.parseInt(textField.getText()));
				heightQuery.setModelCode(ConfUtil.getString("modelCode", ""));
				if (StringUtil.isNotNull(textField1.getText())
						&& StringUtil.isNotNull(textField11.getText())) {
					heightQuery.addCustomAtt(textField1.getText(),
							textField11.getText());
				}
				if (StringUtil.isNotNull(textField2.getText())
						&& StringUtil.isNotNull(textField22.getText())) {
					heightQuery.addCustomAtt(textField2.getText(),
							textField22.getText());
				}

				if (StringUtil.isNotNull(textField3.getText())
						&& StringUtil.isNotNull(textField33.getText())) {
					heightQuery.addCustomAtt(textField3.getText(),
							textField33.getText());
				}
				try {
					SunEcmClientApi clientApi = ConnectionFactory
							.getConnection();
					String resultMsg = clientApi.heightQuery(heightQuery,
							ConfUtil.getString("groupName", ""));
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}
			}
		});
		btnNewButton.setBounds(281, 254, 93, 23);
		add(btnNewButton);

		lblNewLabel_3 = new JLabel("页码");
		lblNewLabel_3.setBounds(49, 179, 54, 15);
		add(lblNewLabel_3);

		textField = new JTextField();
		textField.setText("1");
		textField.setBounds(128, 176, 66, 21);
		add(textField);
		textField.setColumns(10);

		lblNewLabel_4 = new JLabel("每页行数");
		lblNewLabel_4.setBounds(261, 179, 70, 15);
		add(lblNewLabel_4);

		textField_1 = new JTextField();
		textField_1.setText("10");
		textField_1.setBounds(341, 176, 70, 21);
		add(textField_1);
		textField_1.setColumns(10);

	}

}
